import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest, HttpResponse } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { delay } from 'rxjs/operators';

@Injectable()
export class MockHttpInterceptor implements HttpInterceptor {
  intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    // 根据请求路径判断是否是 Post 相关的请求
    // console.log(request.url)
    // if (request.url.endsWith('/post/') && request.method === 'GET') {
    //   // 返回模拟数据
    //   return of(new HttpResponse({ status: 200, body: {post: {name:'s',title:'b',content:'a'}} })).pipe(delay(1500)); // 这里加了一个延迟模拟异步请求
    // } else {
    //   return next.handle(request);
    // }
    return next.handle(request);
  }
}
